/*
 * @lc app=leetcode.cn id=645 lang=cpp
 *
 * [645] 错误的集合
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    vector<int> findErrorNums(vector<int> &nums)
    {
        const int n = nums.size();
        int sum = n * (n + 1) / 2;

        std::sort(nums.begin(), nums.end());
        nums.push_back(nums.size() + 1);
        int err = -1;

        for (int i = 0; i < nums.size() - 1; i++)
        {
            if (nums[i] == nums[i + 1])
            {
                err = nums[i];
                continue;
            }
            sum -= nums[i];
        }
        return {err, sum};
    }
};
// @lc code=end
